home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / spoc88.zip / TADIR.ZIP / DR.ASM < prev   
Assembly Source File  |  1988-06-27  |  3KB  |  80 lines

  1. ;-- Display disk directory.  Written by Tom Swan in Turbo Assembler.
  2.  
  3.                 IDEAL                   ; Switch on Ideal mode
  4.                 %TITLE   "DR.ASM"       ; Comments allowed in titles!
  5.                 DOSSEG                  ; Use standard segments
  6.                 MODEL   small           ; 64K code; 64K data
  7.                 STACK   256             ; Reserve space for stack
  8.  
  9. Attribute       EQU     0               ; Attribute for DirSearch
  10. FileName        EQU     30              ; Offset to file name in DTA
  11. Cr              EQU     13              ; ASCII carriage return
  12. Lf              EQU     10              ; ASCII line feed
  13.  
  14.         DATASEG
  15.  
  16. FileSpec        DB      "*.*", 0        ; ASCIIZ (null-ending) string
  17. CrLf            DB      Cr, Lf, '$'     ; Carriage return, line feed
  18. DTA             DB      128 DUP (?)     ; 128-byte unitialized buffer
  19.  
  20.         CODESEG
  21.  
  22. Start:
  23.         mov     ax,@data                ; Initialize DS to address
  24.         mov     ds,ax                   ;  of data segment
  25.         mov     dx, OFFSET DTA          ; Tell DOS to use our
  26.         mov     ah, 1ah                 ;  disk transter area (DTA)
  27.         int     21h                     ; Call DOS, assign DTA address
  28.  
  29.         mov     bx, OFFSET ListDir      ; Address ListDir subroutine
  30.         mov     cx, Attribute           ; Assign attribute to cx
  31.         mov     dx, OFFSET FileSpec     ; Address wild card string
  32.         call    DirSearch               ; Search and list directory
  33.  
  34.         mov     ax,04C00h               ; End with exit code = 0
  35.         int     21h                     ; Return to DOS
  36.  
  37.  
  38. ;--  Directory Search subroutine
  39. ;    Input: bx = address of subroutine to call for each match
  40. ;           cx = attribute(s) to match
  41. ;        ds:dx = address of ASCIIZ wild card string, e.g. "*.PAS",0
  42.  
  43. PROC    DirSearch
  44.         mov     ah, 4eh                 ; Find-first function number
  45.         jmp     short @@t20             ; Jump into loop
  46. @@t10:
  47.         mov     ah, 4fh                 ; Find-next function number
  48. @@t20:
  49.         int     21h                     ; Call DOS, find first/next
  50.         jc      @@t30                   ; Exit when done
  51.         call    bx                      ; Call user subroutine
  52.         jmp     @@t10                   ; Continue searching 
  53. @@t30:
  54.         ret                             ; Return to caller
  55. ENDP
  56.  
  57.  
  58. ;-----  List directory entry subroutine
  59. ;       Input: DTA contains one directory entry from DirSearch
  60.  
  61. PROC    ListDir
  62.         cld                             ; Clear direction flag
  63.         mov     si, OFFSET DTA+FileName ; Address file name in DTA
  64. @@t10:
  65.         lodsb                           ; al<-name[si]; si<-si+1
  66.         or      al, al                  ; Is al = 0?
  67.         je      @@t20                   ; If al = 0, jump to exit
  68.         mov     ah, 2                   ; Display-char function number
  69.         mov     dl, al                  ; Move char to dl
  70.         int     21h                     ; Call DOS, print character
  71.         jmp     @@t10                   ; Do next character
  72. @@t20:
  73.         mov     ah, 9                   ; Display ASCII$ string 
  74.         mov     dx, OFFSET CrLf         ; Assign offset to CrLf string
  75.         int     21h                     ; Call DOS, print string
  76.         ret                             ; Return to caller
  77. ENDP
  78.  
  79.         END     Start           ; End of text.  Program entry point.
  80.